﻿using LyData.Data;
using System;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_ManagerAdd : System.Web.UI.Page
{
    protected void Add_Click(object sender, EventArgs e)
    {
        if (base.IsValid)
        {
            string[,] includeColumns = new string[,] { { "ManagerName", this.ManagerName.Text.ToString(), "NVarChar", "32" }, { "Password", Function.MD5(this.Password.Text.ToString()), "NVarChar", "32" }, { "PenName", this.PenName.Text.ToString(), "NVarChar", "32" }, { "LoginUrl", this.LoginUrl.Text.ToString(), "NVarChar", "0" } };
            IDb db = new DbFactory().DriverDb();
            db.Open();
            db.Insert("manager", includeColumns);
            db.Close();
            this.Msg.Text = "管理员添加成功！";
            this.Msg.Visible = true;
            this.ManagerName.Text = "";
            this.PenName.Text = "";
        }
    }

    protected void ManagerNameValidator_ServerValidate(object source, ServerValidateEventArgs args)
    {
        IDb db = new DbFactory().DriverDb();
        db.Open();
        int num = db.Scalar("count('ManagerName')", "manager", string.Format("ManagerName='{0}'", args.Value.ToString()));
        db.Close();
        if (num > 0)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!ManagerLogin.ValidateRole("C_ManagerAdd.aspx"))
        {
            this.Msg.CssClass = "errorMsg";
            this.Msg.Text = "您无此权限！";
            this.Msg.Visible = true;
            this.Add.Enabled = false;
        }
        else
        {
            this.Msg.Visible = false;
        }
    }
}
